package com.qingk.easyjava.datasource;

import java.sql.SQLException;

import javax.sql.DataSource;

import org.springframework.context.ApplicationContext;
import org.springframework.context.support.ClassPathXmlApplicationContext;

public class SpringDaoDemo {
	public static void main(String[] args) throws SQLException {
		ApplicationContext context = new ClassPathXmlApplicationContext("applicationContext.xml");
		DataSource ds = (DataSource)context.getBean("dataSource");
		System.out.println("connection from dataSource:" + ds.getConnection());
		
		DataSource ds2 = (DataSource)context.getBean("dataSource2");
		System.out.println("connection from dataSource2:" + ds2.getConnection());
		
		DataSource ds3 = (DataSource) context.getBean("dataSource3");
		System.out.println("connection from dataSource3:" + ds3.getConnection());
		
		BeanDao bd = (BeanDao)context.getBean("beanDao");
		System.out.println(bd.getConnection());
		
		BeanDao bd2 = context.getBean(BeanDao.class);
		System.out.println(bd2.getName());
		
		((ClassPathXmlApplicationContext)context).close();
	}
}
